package antlr.grammars.dot;

import antlr.RecognitionException;
//import antlr.TokenBuffer;
//import antlr.Token;
import antlr.CommonAST;
import antlr.TokenStreamException;
import net.claribole.zgrviewer.dot.*;

import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
//import java.io.InputStream;
import java.io.IOException;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		//System.out.println("OLAAAAAA");
		String f = "/Data/LESI/MESTRADO/Tese/workspace/Teste/teste.dot";
		File file = new File(f);
		try{
		
		DataInputStream input = new DataInputStream(new FileInputStream(file));	
			
		// DOT lexer and parser
		DOTLexer lexer = new DOTLexer(input);
		DOTParser parser = new DOTParser(lexer);
		parser.graph();
		  
		// parsing produces an abstract syntax tree 
		CommonAST ast = (CommonAST) parser.getAST();
		  
		// this AST is transformed into a Graph data structure
		DOTTreeTransformer trans = new DOTTreeTransformer();
		trans.graph(ast);
		CommonAST astTrans = (CommonAST) trans.getAST();
		DOTTreeParser walker = new DOTTreeParser();
		Graph g = walker.graph(astTrans);
		Node[] nod = g.getNodes();
		g.removeNode(nod[0]);
		System.out.println(g.toString());
//		try {
//			BufferedWriter out = new BufferedWriter(new FileWriter("bahaus.dot"));
//			out.write(g.toString());
//			out.close();
//			} 
//		catch (IOException e) 
//			{ 
//			System.out.println("Exception ");}
		
		
		} catch (FileNotFoundException e) {
		    System.out.println("File not found");
		} catch (TokenStreamException e) {
		    e.printStackTrace();
		} catch (RecognitionException e) {
		    e.printStackTrace();
		} catch (Exception e) {
		    e.printStackTrace();
		}
		
		
		
		
		
		System.out.println("FIIIMMMMM");

		
		
	
	}
	
	

}
